<?php
require_once 'TypeArticle.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BDDTypeArticle
 *
 * @author Gael
 */
class BDDTypeArticle extends TypeArticle {
   
    static public function byId($id){
        try{
            $db= getPdo();
            try{ // on essai de lancer une transaction au cas ou elle serait déjà lancer dans une autre fonction
                $db->beginTransaction();
                $commit = true;
            }catch(PDOException $e){
                $commit = false;
                //echo'capture de lancement de transaction :'. $e->getMessage();
            }
            
            $rep = $db->query("select * from typearticle where id=$id" );
            while($data =$rep->fetch()){
                $ta= new BDDTypeArticle($id, $data['nomtype'], $data['modele']);
            }
            if($commit){ $db->commit();}
            $rep->closeCursor();
            return $ta;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
            return false;
        }
    }
    static public function all(){
        try{
            $db= getPdo();
            $tab = array();
            
            $rep = $db->query("select * from typearticle  " );
            while($data =$rep->fetch()){
                $tab[$data['id']    ]=new BDDTypeArticle($data['id'], $data['nomtype'], $data['modele']);
                
            }
            $rep->closeCursor();
            return $tab;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
        }
    } 
   
}

?>
